/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package io.renren.service;

import io.renren.datasource.annotation.DataSource;
import io.renren.modules.lables.dao.MarketMapper;
import io.renren.modules.lables.entity.Market;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * 测试多数据源
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service
@DataSource("slave_1")
public class DorisDataSourceTestService {
    @Autowired
    private MarketMapper marketMapper;

    public void testInsert() {
        String[] brandNames = {"双喜", "五叶神", "椰树", "羊城", "红玫", "好日子", "阿里山", "特美思", "玉溪", "芙蓉王"};
        Random random = new Random();
        for (int i = 0; i < 20; i++) {
            Market market = new Market();
            market.setBrand(brandNames[i%brandNames.length]);
            market.setPrice(random.nextDouble()*100);
            market.setSales((random.nextDouble()*100));
            int result = marketMapper.insert(market);
            assertEquals(1, result);
        }
    }
}